package com.skirmisher.inspection.common.utils;

import com.skirmisher.inspection.common.service.SystemCodeCacheService;
import com.skirmisher.inspection.inspection.testController.ResponseModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName InsGlobalExceptionHandler
 * @Description 参数校验异常拦截
 * @Author hanwangxin
 * @Date 2020/12/11 下午2:53
 * @Version 1.0
 */
@RestControllerAdvice
@Slf4j
@ResponseBody
public class InsGlobalExceptionHandler {


    @ExceptionHandler(MethodArgumentNotValidException.class)
    public ResponseModel handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
        log.error(e.getMessage(), e);
        ResponseModel responseModel = new ResponseModel();
        responseModel.setCode(201);
        responseModel.setMessage(e.getBindingResult().getFieldError().getDefaultMessage());
        return responseModel;
    }
}
